#include <bits/stdc++.h>

using namespace std;

typedef long long ll;
const int mxlc=2520;

ll read(){
    char c;ll r;bool f=0;
    for(c=getchar();c>'9'||c<'0';c=getchar()) if(c=='-') f=1;
    for(r=0;c>='0'&&c<='9';c=getchar()) r=r*10+c-'0';
    if(f) return -r;
    else return r;
}

void print(const ll &x){
    if(x>9) print(x/10);
    putchar(x%10+'0');
}

template <typename T>
inline T gcd(T x,T y){
    while(y){
        T t=x;x=y;y=t%y;
    }
    return x;
}

template <typename T>
inline T Lcm(T x,T y){ return x/gcd(x,y)*y;}

ll _f[20][2525][50];
int val[20];
int ha[2525];

ll f(int digits,int mod,int lcm,bool lim){
    if(digits<=0) if(mod%lcm==0) return 1; else return 0;
    if(!lim&&_f[digits][mod][ha[lcm]]!=-1) return _f[digits][mod][ha[lcm]];

    int mx=lim?val[digits]:9;
    ll ans=0;
    for(int i=0;i<=mx;i++)
        ans+=f(digits-1,(mod*10+i)%mxlc,i?Lcm(lcm,i):lcm,lim&&i==mx);
    if(!lim) _f[digits][mod][ha[lcm]]=ans;
    return ans;
}

ll solve(ll x){
    int len=0;
    while(x) val[++len]=x%10,x/=10;
    return f(len,0,1,1);
}

int main(){
    int T;
    T=read();

    memset(_f,-1,sizeof _f);
    int _end_=1<<9,cnt_ha=0;
    set<int> lcm;
    for(int mask=1;mask<_end_;mask++){
        int lc=1;
        for(int i=1;i<=9;i++) if(mask&(1<<(i-1))) lc=Lcm(lc,i);
        lcm.insert(lc);
    }
    for(auto it=lcm.begin();it!=lcm.end();it++){ //c++ 11
        ha[*it]=cnt_ha++;
    }

    while(T--){
        ll x,y;
        x=read();y=read();
        print(solve(y)-solve(x-1));
        putchar('\n');
    }

    return 0;
}
